# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>

pkgname=diesel-cli
pkgver=2.1.4
pkgrel=1
pkgdesc="CLI for the Diesel crate"
arch=('loong64' 'x86_64')
url="https://diesel.rs/"
license=('MIT' 'Apache')
replaces=('diesel_cli')
depends=(
  'libmariadb.so'
  'libpq.so'
  'libsqlite3.so'
)
makedepends=('cargo')
source=(https://github.com/diesel-rs/diesel/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        Cargo.lock)
sha512sums=('a07e5883f55359d0fb971ff42390f3ca6d683c1fd259557c2fe8b8c220688c098865adf3920597aa5c6a46ab21943d4aa244505ae734fff658819f4090a938b3'
            '0f5b05cf0ff849cce70a13f8153b7c1b0f36bad0320c8edd943a1edd3a3c5d0156f84fc2faeefef8185c356dc47dab472b82eb7d216cf12877aad8d6d5d51fe3')
b2sums=('bb784689cb14847c10300de6eaa4f69868a75f0fd1eacb1d84119c185adf6fdb49d25c52bdb5535df5999356ae19b398a408064ac3f83ed8083ad5aa82310b7b'
        'cfe103c19e2c926a5dc2bd40ca569beef6f05f6ebab5f11daf48b5e1ed272cdec9d6cba283de6cc85c0d9c38410b385960c5bd9426a6bcba5a67f0fcb4efe62b')

prepare() {
  cp Cargo.lock "diesel-${pkgver}"
  cd "diesel-${pkgver}/diesel_cli"
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

updlockfiles() {
  cd "diesel-${pkgver}"
  rm -f Cargo.lock
  cargo update
  cp Cargo.lock "${outdir}/"
}

build() {
  cd "diesel-${pkgver}/diesel_cli"
  RUSTFLAGS="--cap-lints allow" cargo build --frozen --release
}

check() {
  cd "diesel-${pkgver}/diesel_cli"
  # tests require a debug build to be present
  RUSTFLAGS="--cap-lints allow" cargo test --no-default-features --features sqlite
}

package() {
  cd "diesel-${pkgver}"
  install -Dm755 "target/release/diesel" "${pkgdir}/usr/bin/diesel"

  install -d "${pkgdir}/usr/share/bash-completion/completions" \
             "${pkgdir}/usr/share/zsh/site-functions" \
             "${pkgdir}/usr/share/fish/vendor_completions.d"
  "${pkgdir}/usr/bin/diesel" completions bash > "${pkgdir}/usr/share/bash-completion/completions/diesel"
  "${pkgdir}/usr/bin/diesel" completions zsh > "${pkgdir}/usr/share/zsh/site-functions/_diesel"
  "${pkgdir}/usr/bin/diesel" completions fish > "${pkgdir}/usr/share/fish/vendor_completions.d/diesel.fish"

  install -Dm644 LICENSE-MIT -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim:set ts=2 sw=2 et:
